/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.controller;

import br.com.documentar.interfacee.InterfaceController;
import br.com.documentar.model.TelaModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Santos
 */
public class TelaController implements
        InterfaceController<br.com.documentar.model.TelaModel> {

    private final br.com.documentar.DAO.TelaDAO dao = new br.com.documentar.DAO.TelaDAO();

    @Override
    public TelaModel getModel() {
        return new br.com.documentar.model.TelaModel();
    }

    @Override
    public DefaultTableModel insertTableModel(TelaModel model) {
        model.getModelTable().setNumRows(0);
        for (br.com.documentar.model.TelaModel p : dao.getDados(model)) {
            model.getModelTable().addRow(new Object[]{p.getCodigo(),
                p.getProdutoModel().getCodigo() + " - " + p.getProdutoModel().getNome(),
                p.getCategoriaModel().getCodigo() + " - " + p.getCategoriaModel().getCaminhoCompleto(),
                p.getNome(),
                p.getTelaPaiModel().getCodigo() + " - " + p.getTelaPaiModel().getCaminhoCompletoSemItemTela(),
                p.getAtivo(), p.getTemFilho()
            });
        }
        return model.getModelTable();
    }

    @Override
    public DefaultTableModel getDadosTableModel(TelaModel model) {
        return insertTableModel(model);
    }

    @Override
    public boolean setDados(TelaModel model) {
        return dao.setDados(model);
    }

    @Override
    public DefaultComboBoxModel getDadosComboBoxModel(TelaModel model) {
        return insertComboBoxModel(model);
    }

    @Override
    public DefaultComboBoxModel insertComboBoxModel(TelaModel model) {
        for (br.com.documentar.model.TelaModel p : dao.getDados(model)) {
            model.getModelComboBox().addElement(p.getCodigo() + " - " + p.getCaminhoCompletoTela());
        }
        return model.getModelComboBox();
    }
}
